<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <th:block th:include="include :: header('现货交易记录列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <div class="col-sm-12 search-collapse">
            <form id="formId" class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">名称：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" placeholder="请输入名称"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">代码：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="code" placeholder="请输入代码"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">买入价格：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="buyPrice" placeholder="请输入买入价格"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">买入数量：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="buyCount" placeholder="请输入买入数量"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">卖出价格：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="sellPrice" placeholder="请输入卖出价格"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">卖出数量：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="sellCount" placeholder="请输入卖出数量"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">汇总：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="marker" placeholder="请输入汇总"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">成功失败标识：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="stateFlag" placeholder="请输入成功失败标识"
                            class="layui-input" />
                    </div>
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="stockSpotRecord-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="stockSpotRecord-table" lay-filter="stockSpotRecord-table"></table>
        <script type="text/html" id="stockSpotRecord-toolbar">
            <button sec:authorize="hasPermission('/sys/stockSpotRecord/add','sys:stockSpotRecord:add')"
                    class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
                新增
            </button>
            <button sec:authorize="hasPermission('/sys/stockSpotRecord/remove','sys:stockSpotRecord:remove')"
                    class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
                <i class="layui-icon layui-icon-delete"></i>
                删除
            </button>
        </script>
        <script type="text/html" id="stockSpotRecord-bar">
            <button sec:authorize="hasPermission('/sys/stockSpotRecord/edit','sys:stockSpotRecord:edit')"
                    class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i
                    class="layui-icon layui-icon-edit"></i>
            </button>
            <button sec:authorize="hasPermission('/sys/stockSpotRecord/remove','sys:stockSpotRecord:remove')"
                    class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i
                    class="layui-icon layui-icon-delete"></i>
            </button>
        </script>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery', 'dictionary', 'popup'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let popup = layui.popup;

        let prefix = "/sys/stockSpotRecord/";

        let cols = [
            [
                {type: 'checkbox'},
                        {
                            field: 'id',
                            title: '持有成交量'
                        },
                        {
                            field: 'name',
                            title: '名称'
                        },
                        {
                            field: 'code',
                            title: '代码'
                        },
                        {
                            field: 'buyPrice',
                            title: '买入价格'
                        },
                        {
                            field: 'buyCount',
                            title: '买入数量'
                        },
                        {
                            field: 'buyTime',
                            title: '买入时间'
                        },
                        {
                            field: 'sellPrice',
                            title: '卖出价格'
                        },
                        {
                            field: 'sellCount',
                            title: '卖出数量'
                        },
                        {
                            field: 'sellTime',
                            title: '卖出时间'
                        },
                        {
                            field: 'marker',
                            title: '汇总'
                        },
                        {
                            field: 'stateFlag',
                            title: '成功失败标识'
                        },
                        {
                            field: 'type',
                            title: '类型'
                        },
                        {
                            field: 'strategyType',
                            title: '策略类型'
                        },
                {title: '操作', toolbar: '#stockSpotRecord-bar', align: 'center', width: 130}
            ]
        ]

        table.render({
            elem: '#stockSpotRecord-table',
            url: prefix + 'data',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#stockSpotRecord-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        table.on('tool(stockSpotRecord-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        table.on('toolbar(stockSpotRecord-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        form.on('submit(stockSpotRecord-query)', function (data) {
            table.reload('stockSpotRecord-table', {where: data.field})
            return false;
        });

        window.add = function () {
            layer.open({
                type: 2,
                title: '新增现货交易记录',
                shade: 0.1,
                area: ['550px', '500px'],
                content: prefix + 'add'
            });
        }

        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改现货交易记录',
                shade: 0.1,
                area: ['550px', '500px'],
                content: prefix + 'edit?id=' + obj.data['id']
            });
        }

        window.remove = function (obj) {
            layer.confirm('确定要删除该现货交易记录', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: prefix + "remove/" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.batchRemove = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些现货交易记录', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: prefix + "batchRemove",
                    dataType: 'json',
                    data: {"ids": ids},
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('stockSpotRecord-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.refresh = function (param) {
            table.reload('stockSpotRecord-table', {where: param});
        }
    })
</script>
</body>
</html>